package object3.package2;

public class Test {
    public static void main(String[] args) {
//        String [] shapes = {"circle","flower","rectangle"};
        //这样写,代码的圈复杂度就比较高
//        for(String shapeName:shapes){
//            if(shapeName.equals("circle")){
//                Shape shape = new Circle();
//                shape.draw();
//            } else if (shapeName.equals("flower")) {
//                Shape shape = new Flower();
//                shape.draw();
//            }else if(shapeName.equals("rectangle")){
//                Shape shape = new Rect();
//                shape.draw();
//            }
//        }

        //可以基于多态,去优化上述代码
        Shape [] shapes = {new Circle(),new Flower(),new Rect()};
        for(Shape shape : shapes){//遍历写法
            shape.draw();
        }
        for(int i = 0;i < shapes.length;i++){//正常写法
            shapes[i].draw();
        }
    }
}
